//
//  CWSportCameraVC.m
//  大神专制黑马行
//
//  Created by chenWei on 2017/5/17.
//  Copyright © 2017年 陈伟. All rights reserved.
//

#import "CWSportCameraVC.h"

@interface CWSportCameraVC ()

@property (strong, nonatomic) IBOutletCollection(NSLayoutConstraint) NSArray *previewConstraintArr;



@end

@implementation CWSportCameraVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
}


//监听拍照按钮的点击
- (IBAction)takePhotoButtonClick:(id)sender {
    //折叠
    [self foldAnimation:YES];
    
    //线程延迟 0.5秒之后执行不折叠
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self foldAnimation:NO];
    });
    
}


/**
 折叠动画

 @param isFold 是否折叠
 */
- (void)foldAnimation:(BOOL)isFold
{
  //  NSLog(@"%@",self.previewConstraintArr);
    
    
    if (isFold == YES) {
        //折叠
        //让优先级高的约束不安装，则系统会自动加载优先级低的
        [NSLayoutConstraint deactivateConstraints:self.previewConstraintArr];
        
    }else {
        //不折叠
        //安装优先级高的
        [NSLayoutConstraint activateConstraints:self.previewConstraintArr];
        
    }
    
    //AutoLayout的原理就是在动画中实现 layoutIfNeeded
    [UIView animateWithDuration:0.5 animations:^{
        [self.view layoutIfNeeded];
    }];
    
}





@end
